package com.emip.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.emip.bean.ImageBean;
import com.emip.dao.BaseDAO;
import com.emip.dao.ImageDAO;


@Repository("imageDAO")
public class ImageDAOImpl extends BaseDAO implements ImageDAO {

	public void add(ImageBean image) {
		getHibernateTemplate().save(image);
	}

	public List<ImageBean> findByDate(String siteId, String startDate, String endDate,
			int page, int size) {
		startDate += " 00:00:00";
		endDate += " 23:59:59";
		String hql = "from ImageBean entity where entity.site.id = '" +
				siteId + "' and entity.genTime >= to_date('" + 
				startDate + "', 'YYYY-MM-DD hh24:mi:ss') and " +
				"entity.genTime <= to_date('" + endDate + 
				"', 'YYYY-MM-DD hh24:mi:ss') order by entity.genTime";
		return getEntities(ImageBean.class, hql, page, size);
	}

	public long getCount(String siteId, String startDate, String endDate) {
		startDate += " 00:00:00";
		endDate += " 23:59:59";
		String hql = "select count(*) from ImageBean entity where entity.site.id = '" +
				siteId + "' and entity.genTime >= to_date('" + 
				startDate + "', 'YYYY-MM-DD hh24:mi:ss') and " +
				"entity.genTime <= to_date('" + endDate + 
				"', 'YYYY-MM-DD hh24:mi:ss')";
		return (Long)getHibernateTemplate().find(hql).listIterator().next();
	}

}
